package com.elock.intf.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.dao.impl.DaoCenter;
import com.elock.base.core.util.ConvertUtil;

/**
 * Dao - 锁
 * @author 仁德
 */
@Repository("intfWarningMessageProcessDao")
public class IntfWarningMessageProcessDao extends DaoCenter {

	public Page<Map<String, Object>> findPage(Pageable pageable, Object[] args) {

		List<Object> list = new ArrayList<Object>();

		String companyCode = (String) args[0];
		String terminalNum = (String) args[1];
		String elockNum = (String) args[2];
		Integer isProcess = (Integer) args[3];

		StringBuilder sql = new StringBuilder();
		sql.append("select w.*,e.car_number,e.position,e.seq,e.berth");
		sql.append(" from warning_message_process w");
		sql.append(" left join elock_car e on w.elock_num=e.elock_num");
		sql.append(" and w.company_info_id=e.company_info_id");
		sql.append(" left join company_info c on c.id=w.company_info_id");
		sql.append(" where 1=1");
		if (companyCode != null) {
			sql.append(" and c.company_code=?");
			list.add(companyCode);
		}
		if (isProcess != null) {
			sql.append(" and w.is_process=?");
			list.add(isProcess);
		}
		if (!ConvertUtil.isEmpty(elockNum)) {
			sql.append(" and w.elock_num like ?");
			list.add("%" + elockNum + "%");
		}
		if (!ConvertUtil.isEmpty(terminalNum)) {
			sql.append(" and w.terminal_num like ?");
			list.add("%" + terminalNum + "%");
		}
		sql.append(" order by w.create_date desc");

		Object[] objs = new Object[list.size()];
		for (int i = 0; i < list.size(); i++) {
			objs[i] = list.get(i);
		}

		Page<Map<String, Object>> getPage = getNativeDao().findPageMap(sql.toString(),
				objs,
				pageable);

		return getPage;

	}

}